#ifndef CRYPT_H_
#define CRYPT_H_

#include <openssl/evp.h>

struct crypt {
    int                 flags;
    const EVP_CIPHER *  cipher;
    unsigned char       key[EVP_MAX_KEY_LENGTH];
    size_t              keylen;
    unsigned char       deciv[EVP_MAX_IV_LENGTH];
    size_t              decivlen;
    EVP_CIPHER_CTX      enc;
    EVP_CIPHER_CTX      dec;
};

void crypt_env_init();
int crypt_init(struct crypt *ctx, const char *ciphername, const char *passwd);
void crypt_destroy(struct crypt *ctx);
ssize_t crypt_en(struct crypt *ctx, void *out, int outl, const void *in, int inl);
ssize_t crypt_de(struct crypt *ctx, void *in, int inl, void *out, int outl);

#endif /* CRYPT_H_ */
